package com.jdbc.shili;

import java.sql.*;

public class CreateDatabase {

    //JDBC driver name and database URL
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://192.168.189.143:33061/hibernate";


    //Database credentials
    static final String USER = "root";
    static final String PASS = "123456";


    public static void main(String[] args) throws SQLException {
        Connection connection = null;
        PreparedStatement preparedStatement = null;

        try {
            Class.forName(JDBC_DRIVER);

            connection = DriverManager.getConnection(DB_URL, USER, PASS);

            String sql = "CREATE DATABASE jdbc_db";

            preparedStatement = connection.prepareStatement(sql);


            preparedStatement.executeUpdate();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //此处用于关闭连接
            if(preparedStatement != null) {
                preparedStatement.close();
            }
        }

    }

}
